// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: UFO Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 71 : TYPE_UFO

// Function declarations
reserve function UFO_DebugDraw
reserve function UFO_DebugSpawn

// Static Values

// Tables

function UFO_DebugDraw
	DrawSprite(0)
end function


function UFO_DebugSpawn
	CreateTempObject(TypeName[UFO], 0, object.xpos, object.ypos)
	object[tempObjectPos].type = TypeName[Blank Object]
	if object[11].type == TypeName[UFO]
		ResetObjectEntity(11, TypeName[Blank Object], 0, 0, 0)
	else
		ResetObjectEntity(11, TypeName[UFO], 0, 0, 0)
		object[11].priority = PRIORITY_ACTIVE
		object[11].drawOrder = 1
		object[11].inkEffect = INK_ALPHA
	end if
end function


event ObjectMain
	object.frame = object.animationTimer
	object.frame >>= 3
	object.animationTimer++
	object.animationTimer &= 63
end event


event ObjectDraw
	if screen.yoffset < 640
		temp0 = screen.xoffset
		temp0 >>= 3
		temp0 &= 127
		FlipSign(temp0)
		temp1 = tileLayer[1].scrollPos
		temp1 /= -0x10000
		temp1 += 32
		temp2 = screen.xsize
		temp2 += 32
		temp5 = oscillation
		temp5 <<= 1
		while temp0 < temp2
			temp3 = temp0
			temp3 += temp5
			Sin(temp4, temp3)
			temp4 >>= 5
			temp4 += temp1
			Cos(object.alpha, temp3)
			object.alpha >>= 2
			object.alpha += 128
			DrawSpriteScreenFX(object.frame, FX_INK, temp0, temp4)
			temp0 += 64
		loop
		temp0 = screen.xoffset
		temp0 >>= 4
		temp0 &= 127
		temp0 += 32
		FlipSign(temp0)
		while temp0 < temp2
			temp3 = temp0
			temp3 += temp5
			Sin(temp4, temp3)
			temp4 >>= 5
			FlipSign(temp4)
			temp4 += temp1
			Cos(object.alpha, temp3)
			object.alpha >>= 2
			FlipSign(object.alpha)
			object.alpha += 128
			DrawSpriteScreenFX(object.frame, FX_INK, temp0, temp4)
			temp0 += 64
		loop
	end if
end event


event ObjectStartup
	LoadSpriteSheet("MZ/Objects.gif")
	SpriteFrame(-16, -8, 32, 16, 123, 303)
	SpriteFrame(-16, -8, 32, 16, 156, 230)
	SpriteFrame(-16, -12, 32, 24, 123, 247)
	SpriteFrame(-16, -15, 32, 30, 123, 272)
	SpriteFrame(-16, -16, 32, 32, 130, 355)
	SpriteFrame(-16, -15, 32, 30, 156, 273)
	SpriteFrame(-16, -12, 32, 25, 156, 247)
	SpriteFrame(-16, -8, 32, 16, 123, 230)
	SetTableValue(TypeName[UFO], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(UFO_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(UFO_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
